package com.ruoyi.business.controller;

import com.ruoyi.business.domain.BusGzzdgl;
import com.ruoyi.business.domain.vo.BusGzzdglSaveVO;
import com.ruoyi.business.domain.vo.BusZdgzSaveVO;
import com.ruoyi.business.service.IBusGzzdglService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规则制度管理Controller
 *
 * @author yaowei
 * @date 2021-07-01
 */
@Api(description = "规则制度管理")
@RestController
@RequestMapping("/business/gzzdgl")
public class BusGzzdglController extends BaseController {
    @Autowired
    private IBusGzzdglService busGzzdglService;

    /**
     * 查询规则制度管理列表
     */
    @ApiOperation("规章制度列表")
    @GetMapping("/list")
    public TableDataInfo list(BusGzzdgl busGzzdgl) {
        startPage();
        List<BusGzzdgl> list = busGzzdglService.selectBusGzzdglList(busGzzdgl);
        return getDataTable(list);
    }

    /**
     * 导出规则制度管理列表
     */
    @Log(title = "规则制度管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusGzzdgl busGzzdgl) {
        List<BusGzzdgl> list = busGzzdglService.selectBusGzzdglList(busGzzdgl);
        ExcelUtil<BusGzzdgl> util = new ExcelUtil<BusGzzdgl>(BusGzzdgl.class);
        return util.exportExcel(list, "gzzdgl");
    }

    /**
     * 获取规则制度管理详细信息
     */
    @ApiOperation("根据ID查找规章制度")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busGzzdglService.selectBusGzzdglById(id));
    }

    /**
     * 新增规则制度管理
     */
    @ApiOperation("规章制度新增/修改")
    @Log(title = "规则制度管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusGzzdglSaveVO busGzzdglSaveVO) {
        Long id = busGzzdglSaveVO.getId();
        if (id == null) {
            return toAjax(busGzzdglService.insertBusGzzdgl(busGzzdglSaveVO));
        } else {
            return toAjax(busGzzdglService.updateBusGzzdgl(busGzzdglSaveVO));
        }
    }

    /**
     * 修改规则制度管理
     */
    @Log(title = "规则制度管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusGzzdglSaveVO busGzzdglSaveVO) {
        return toAjax(busGzzdglService.updateBusGzzdgl(busGzzdglSaveVO));
    }

    /**
     * 删除规则制度管理
     */
    @ApiOperation("删除规则制度管理")
    @Log(title = "规则制度管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(busGzzdglService.deleteBusGzzdglByIds(ids));
    }
}
